﻿using System;
using System.Reflection;

namespace FlashPay.Util.StatusCode
{
    public enum StatusCode
    {
        COMPANY_DELETE_CANNOT_FIND_DATA                                 = 100,
        COMPANY_DELETE_EXIST_ROLE_DATA                                  = 101,
        COMPANY_DELETE_EXIST_USER_DATA                                  = 102,
        COMPANY_EDIT_CANNOT_FIND_DATA                                   = 103,
        COMPANY_EDIT_EXIST_NAME                                         = 104,
        COMPANY_EDIT_NAME_TOO_LONG                                      = 105,
        COMPANY_ADD_CANNOT_FIND_DATA                                    = 106,
        COMPANY_ADD_EXIST_NAME                                          = 107,
        COMPANY_ADD_NAME_TOO_LONG                                       = 108,
        COMPANY_CHANGE_COMPANY_MENU_TYPE_CANNOT_FIND_DATA               = 109,
        COMPANY_CHANGE_COMPANY_STATUS_CANNOT_FIND_DATA                  = 110,


        ORDER_EDIT_CANNOT_FIND_DATA                                     = 200,
        ORDER_EDIT_NO_DATA_OWNERSHIP                                    = 201,
        ORDER_EDIT_DEPOSIT_PASSED                                       = 202,
        ORDER_EDIT_PAY_PASSED                                           = 203,
        ORDER_EDIT_RECEIPT_DATE_CANNOT_FIND_DATA                        = 204,
        ORDER_EDIT_RECEIPT_DATE_NO_DATA_OWNERSHIP                       = 205,
        ORDER_EDIT_RECEIPT_DATE_PAY_PASSED                              = 206,
        ORDER_EDIT_PAY_DATE_CANNOT_FIND_DATA                            = 207,
        ORDER_EDIT_PAY_DATE_NO_DATA_OWNERSHIP                           = 208,
        ORDER_EDIT_PAY_DATE_PAY_PASSED                                  = 209,
        ORDER_DELETE_CANNOT_FIND_DATA                                   = 210,
        ORDER_DELETE_NO_DATA_OWNERSHIP                                  = 211,
        ORDER_DELETE_DEPOSIT_PASSED                                     = 212,
        ORDER_PASS_DEPOSIT_CANNOT_FIND_DATA                             = 213,
        ORDER_PASS_DEPOSIT_NO_DATA_OWNERSHIP                            = 214,
        ORDER_PASS_DEPOSIT_DEPOSIT_PASSED                               = 215,
        ORDER_PASS_DEPOSIT_NO_SUB_ORDER                                 = 216,
        ORDER_PASS_PAY_CANNOT_FIND_DATA                                 = 217,
        ORDER_PASS_PAY_NO_DATA_OWNERSHIP                                = 218,
        ORDER_PASS_PAY_DEPOSIT_NO_PASS                                  = 219,
        ORDER_PASS_PAY_RECEIPT_NO_PASS                                  = 220,
        ORDER_PASS_PAY_PAY_PASSED                                       = 221,
        ORDER_PASS_PAY_BANK_CARD_DATA_NOT_MATCH                         = 222,
        ORDER_PASS_RECEIPT_DEPOSIT_NO_PASS                              = 223,
        ORDER_PASS_RECEIPT_RECEIPT_PASSED                               = 224,


        ORDER_DETAIL_ADD_CANNOT_FIND_DATA                               = 300,
        ORDER_DETAIL_ADD_NO_DATA_OWNERSHIP                              = 301,
        ORDER_DETAIL_ADD_ORDER_HAS_BEEN_COMPLETED                       = 302,
        ORDER_DETAIL_EDIT_CANNOT_FIND_DATA                              = 303,
        ORDER_DETAIL_EDIT_NO_DATA_OWNERSHIP                             = 304,
        ORDER_DETAIL_EDIT_DEPOSIT_PASSED                                = 305,
        ORDER_DETAIL_EDIT_PAY_PASSED                                    = 306,
        ORDER_DETAIL_EDIT_ACTUAL_COUNT_AND_UNIT_PRICE_CANNOT_FIND_DATA  = 307,
        ORDER_DETAIL_EDIT_ACTUAL_COUNT_AND_UNIT_PRICE_NO_DATA_OWNERSHIP = 308,
        ORDER_DETAIL_EDIT_ACTUAL_COUNT_AND_UNIT_PRICE_PAY_PASSED        = 309,
        ORDER_DETAIL_DELETE_CANNOT_FIND_DATA                            = 310,
        ORDER_DETAIL_DELETE_NO_DATA_OWNERSHIP                           = 311,
        ORDER_DETAIL_DELETE_PAY_PASSED                                  = 312,

        BANK_INFO_ADD_EXIST_DATA                                        = 400,
        BANK_INFO_EDIT_CANNOT_FIND_DATA                                 = 401,

        SYS_CONFIG_ADD_EXIST_DATA                                       = 500,
        SYS_CONFIG_EDIT_CANNOT_FIND_DATA                                = 501,
        
        ILLEGAL_REQUEST                                                 = -1,
        SYSTEM_ERROR                                                    = -2
    }

    public abstract class StatusCodeFactory
    {
        public void BuildStatus<T>(StatusCode status, T model)
        {
            PropertyInfo[] infos = model.GetType().GetProperties();
            foreach (PropertyInfo info in infos)
            {
                switch (info.Name.ToLower())
                {
                    case "code":
                        info.SetValue(model, GetCode(status));
                        break;

                    case "message":
                        info.SetValue(model, GetMessage(status));
                        break;
                }
            }
        }

        public void BuildStatus(StatusCode status, out String code, out String message)
        {
            code = GetCode(status);
            message = GetMessage(status);
        }

        private String GetCode(StatusCode status)
        {
            switch (status)
            {
                case StatusCode.COMPANY_DELETE_CANNOT_FIND_DATA:
                    return "100";

                case StatusCode.COMPANY_DELETE_EXIST_ROLE_DATA:
                    return "101";

                case StatusCode.COMPANY_DELETE_EXIST_USER_DATA:
                    return "102";

                case StatusCode.COMPANY_EDIT_CANNOT_FIND_DATA:
                    return "103";

                case StatusCode.COMPANY_EDIT_EXIST_NAME:
                    return "104";

                case StatusCode.COMPANY_EDIT_NAME_TOO_LONG:
                    return "105";

                case StatusCode.COMPANY_ADD_CANNOT_FIND_DATA:
                    return "106";

                case StatusCode.COMPANY_ADD_EXIST_NAME:
                    return "107";

                case StatusCode.COMPANY_ADD_NAME_TOO_LONG:
                    return "108";

                case StatusCode.COMPANY_CHANGE_COMPANY_MENU_TYPE_CANNOT_FIND_DATA:
                    return "109";

                case StatusCode.COMPANY_CHANGE_COMPANY_STATUS_CANNOT_FIND_DATA:
                    return "110";

                case StatusCode.ORDER_EDIT_CANNOT_FIND_DATA:
                    return "200";

                case StatusCode.ORDER_EDIT_NO_DATA_OWNERSHIP:
                    return "201";

                case StatusCode.ORDER_EDIT_DEPOSIT_PASSED:
                    return "202";

                case StatusCode.ORDER_EDIT_PAY_PASSED:
                    return "203";

                case StatusCode.ORDER_EDIT_RECEIPT_DATE_CANNOT_FIND_DATA:
                    return "204";

                case StatusCode.ORDER_EDIT_RECEIPT_DATE_NO_DATA_OWNERSHIP:
                    return "205";

                case StatusCode.ORDER_EDIT_RECEIPT_DATE_PAY_PASSED:
                    return "206";

                case StatusCode.ORDER_EDIT_PAY_DATE_CANNOT_FIND_DATA:
                    return "207";

                case StatusCode.ORDER_EDIT_PAY_DATE_NO_DATA_OWNERSHIP:
                    return "208";

                case StatusCode.ORDER_EDIT_PAY_DATE_PAY_PASSED:
                    return "209";

                case StatusCode.ORDER_DELETE_CANNOT_FIND_DATA:
                    return "210";

                case StatusCode.ORDER_DELETE_NO_DATA_OWNERSHIP:
                    return "211";

                case StatusCode.ORDER_DELETE_DEPOSIT_PASSED:
                    return "212";

                case StatusCode.ORDER_PASS_DEPOSIT_CANNOT_FIND_DATA:
                    return "213";

                case StatusCode.ORDER_PASS_DEPOSIT_NO_DATA_OWNERSHIP:
                    return "214";

                case StatusCode.ORDER_PASS_DEPOSIT_DEPOSIT_PASSED:
                    return "215";

                case StatusCode.ORDER_PASS_DEPOSIT_NO_SUB_ORDER:
                    return "216";

                case StatusCode.ORDER_PASS_PAY_CANNOT_FIND_DATA:
                    return "217";

                case StatusCode.ORDER_PASS_PAY_NO_DATA_OWNERSHIP:
                    return "218";

                case StatusCode.ORDER_PASS_PAY_DEPOSIT_NO_PASS:
                    return "219";

                case StatusCode.ORDER_PASS_PAY_RECEIPT_NO_PASS:
                    return "220";

                case StatusCode.ORDER_PASS_PAY_PAY_PASSED:
                    return "221";

                case StatusCode.ORDER_PASS_PAY_BANK_CARD_DATA_NOT_MATCH:
                    return "222";

                case StatusCode.ORDER_PASS_RECEIPT_DEPOSIT_NO_PASS:
                    return "223";

                case StatusCode.ORDER_PASS_RECEIPT_RECEIPT_PASSED:
                    return "224";

                case StatusCode.ORDER_DETAIL_ADD_CANNOT_FIND_DATA:
                    return "300";

                case StatusCode.ORDER_DETAIL_ADD_NO_DATA_OWNERSHIP:
                    return "301";

                case StatusCode.ORDER_DETAIL_ADD_ORDER_HAS_BEEN_COMPLETED:
                    return "302";

                case StatusCode.ORDER_DETAIL_EDIT_CANNOT_FIND_DATA:
                    return "303";

                case StatusCode.ORDER_DETAIL_EDIT_NO_DATA_OWNERSHIP:
                    return "304";

                case StatusCode.ORDER_DETAIL_EDIT_DEPOSIT_PASSED:
                    return "305";

                case StatusCode.ORDER_DETAIL_EDIT_PAY_PASSED:
                    return "306";

                case StatusCode.ORDER_DETAIL_EDIT_ACTUAL_COUNT_AND_UNIT_PRICE_CANNOT_FIND_DATA:
                    return "307";

                case StatusCode.ORDER_DETAIL_EDIT_ACTUAL_COUNT_AND_UNIT_PRICE_NO_DATA_OWNERSHIP:
                    return "308";

                case StatusCode.ORDER_DETAIL_EDIT_ACTUAL_COUNT_AND_UNIT_PRICE_PAY_PASSED:
                    return "309";

                case StatusCode.ORDER_DETAIL_DELETE_CANNOT_FIND_DATA:
                    return "310";

                case StatusCode.ORDER_DETAIL_DELETE_NO_DATA_OWNERSHIP:
                    return "311";

                case StatusCode.ORDER_DETAIL_DELETE_PAY_PASSED:
                    return "312";

                case StatusCode.BANK_INFO_ADD_EXIST_DATA:
                    return "400";

                case StatusCode.BANK_INFO_EDIT_CANNOT_FIND_DATA:
                    return "401";

                case StatusCode.SYS_CONFIG_ADD_EXIST_DATA:
                    return "500";

                case StatusCode.SYS_CONFIG_EDIT_CANNOT_FIND_DATA:
                    return "501";

                case StatusCode.ILLEGAL_REQUEST:
                    return "-1";

                case StatusCode.SYSTEM_ERROR:
                    return "-2";

                default:
                    throw new Exception("The status code is no definition.");
            }
        }

        protected abstract String GetMessage(StatusCode status);
    }
}